<template>
    <el-dropdown :hide-on-click="false" @visible-change="dropDownShowChange($event)">
        <el-button plain icon="el-icon-tickets"  :disabled="isUse == '1' ? true : false">
            批量操作
        </el-button>
        <el-dropdown-menu slot="dropdown" class="ticketsform">
            <el-dropdown-item><label>是否可录入：</label><el-switch v-model="ticketsform.isInput"
                    @change="chanageFieldCaptionTap('isInput')" active-value="1" inactive-value="0"></el-switch></el-dropdown-item>
            <el-dropdown-item><label>是否可修改：</label><el-switch v-model="ticketsform.isUpdate"
                    @change="chanageFieldCaptionTap('isUpdate')" active-value="1" inactive-value="0"></el-switch></el-dropdown-item>

            <el-dropdown-item><label>是否档号字段：</label><el-switch v-model="ticketsform.isArchiveNo"
                    @change="chanageFieldCaptionTap('isArchiveNo')" active-value="1" inactive-value="0"></el-switch></el-dropdown-item>
            <el-dropdown-item><label>是否非空：</label><el-switch v-model="ticketsform.isNoEmpty"
                    @change="chanageFieldCaptionTap('isNoEmpty')" active-value="1" inactive-value="0"></el-switch></el-dropdown-item>
            <el-dropdown-item><label>是否隐藏：</label><el-switch v-model="ticketsform.isHidden"
                    @change="chanageFieldCaptionTap('isHidden')" active-value="1" inactive-value="0"></el-switch></el-dropdown-item>
            <el-dropdown-item><label>是否可导出：</label><el-switch v-model="ticketsform.isExport"
                    @change="chanageFieldCaptionTap('isExport')" active-value="1" inactive-value="0"></el-switch></el-dropdown-item>
            <el-dropdown-item><label>元数据：</label><el-switch v-model="ticketsform.isMetadata"
                    @change="chanageFieldCaptionTap('isMetadata')" active-value="1" inactive-value="0"></el-switch></el-dropdown-item>
        </el-dropdown-menu>
    </el-dropdown>
</template>

<script>
import {updateCateMdataList, updateCateMdataListBatch} from "@/api/archive/archivesCategory.js";
import {updateMdata, updateMdataBatch} from "@/api/manage/metaData";
export default {

    // cateIsType  0=应用定义档案门类里面的元数据方案明细列表添加    1=应用定义里面的元数据方案明细列表添加  2=立档单位下面的模板管理的元数据方案添加
    watch: {
        cateIsType: {
            deep: true,
            immediate: true, // 监听到后，立即执行 handler方法
            handler: function (newVal, oldVal) {
                this.cateIsType=newVal;
            },

        }
    },
    props: ["isUse","ids","cateIsType","list"],
    data() {
        return {

            //批量操作
            ticketsform: {
                isInput: false, //是否可录入
            },
        }
    },
    methods: {
        //修改元数据明细批量操作
        chanageFieldCaptionTap(val) {
            console.log(val,"--------------------")
            var data = "";
            if (this.ids.length !== 0) {
                
                for(var i in  Object.keys(this.ticketsform)){
                    if(Object.keys(this.ticketsform)[i]!=val){
                        this.ticketsform[Object.keys(this.ticketsform)[i]]=undefined
                    }
                    
                }
                this.ticketsform.ids = this.ids.toString()
                if(this.cateIsType=="0"){
                  updateCateMdataListBatch(this.ticketsform).then(response => {
                    this.$modal.msgSuccess("修改成功");
                    this.list.filter(v => this.ids.some(val => {
                        if (val === v.id) {
                            if(this.ticketsform.isInput!=undefined){
                                v.isInput = this.ticketsform.isInput
                            }
                            if(this.ticketsform.isUpdate!=undefined){
                                v.isUpdate = this.ticketsform.isUpdate
                            }
                            if(this.ticketsform.isArchiveNo!=undefined){
                                v.isArchiveNo = this.ticketsform.isArchiveNo
                            }
                            if( this.ticketsform.isNoEmpty!=undefined){
                                v.isNoEmpty = this.ticketsform.isNoEmpty
                            }
                            if(this.ticketsform.isHidden!=undefined){
                                v.isHidden = this.ticketsform.isHidden
                            }

                            if(this.ticketsform.isExport!=undefined){
                                v.isExport = this.ticketsform.isExport
                            }

                            if(this.ticketsform.isMetadata!=undefined){
                                v.isMetadata = this.ticketsform.isMetadata
                            }

                        }
                    }))

                });
            }else if(this.cateIsType=="2"){
                  updateMdataBatch(this.ticketsform).then(response => {
                    this.$modal.msgSuccess("修改成功");
                    this.list.filter(v => this.ids.some(val => {
                        if (val === v.id) {
                            if(this.ticketsform.isInput!=undefined){
                                v.isInput = this.ticketsform.isInput
                            }
                            if(this.ticketsform.isUpdate!=undefined){
                                v.isUpdate = this.ticketsform.isUpdate
                            }
                            if(this.ticketsform.isArchiveNo!=undefined){
                                v.isArchiveNo = this.ticketsform.isArchiveNo
                            }
                            if( this.ticketsform.isNoEmpty!=undefined){
                                v.isNoEmpty = this.ticketsform.isNoEmpty
                            }
                            if(this.ticketsform.isHidden!=undefined){
                                v.isHidden = this.ticketsform.isHidden
                            }

                            if(this.ticketsform.isExport!=undefined){
                                v.isExport = this.ticketsform.isExport
                            }

                            if(this.ticketsform.isMetadata!=undefined){
                                v.isMetadata = this.ticketsform.isMetadata
                            }

                        }
                    }))
                });
            }
            } else {

                this.$modal.msgError("请选择修改的数据")
                this.ticketsform = {
                    isInput: undefined, //是否可录入0=否,1=是
                    isUpdate: undefined, //是否可修改0=否,1=是
                    isArchiveNo: undefined, //是否档号字段0=否,1=是
                    isNoEmpty: undefined, //是否非空0=否,1=是
                    isHidden: undefined, //是否隐藏0=否,1=是
                    isExport: undefined, //是否可导出0=否,1=是
                    isMetadata: undefined, //是否元数据0=否,1=是
                }
            }

            this.$emit("chanageFieldCaptionTap",this.list)
        },
        //批量操作下拉框隐藏时触发
        dropDownShowChange(event) {
            if (!event) {
                this.ticketsform = {
                    isInput: undefined, //是否可录入0=否,1=是
          isUpdate: undefined, //是否可修改0=否,1=是
          isArchiveNo: undefined, //是否档号字段0=否,1=是
          isNoEmpty: undefined, //是否非空0=否,1=是
          isHidden: undefined, //是否隐藏0=否,1=是
          isExport: undefined, //是否可导出0=否,1=是
          isMetadata: undefined, //是否元数据0=否,1=是
                }
            }
        },
    }
}
</script>
